/***********************************************************************
 * @file:        xxx.c
 * @author:      guangjieMVP
 * @version:     v1.00.00
 * @date:        2020-xx-xx
 * @github:      https://github.com/guangjieMVP
 * @brief: 
***********************************************************************/
#ifndef _STACK_VALIDATOR_H_
#define _STACK_VALIDATOR_H_
#include "string.h"

//定义校验器类
typedef struct _stack_validator
{
    int (*check)(struct _stack_validator *s, int val);   //检查逻辑抽象为一个类
}stack_validator_t;

/***********************************************************************
 * @brief:         校验类初始化
 * @param[in]:     None
 * @retval[out]:   None
 * @author:        guangjieMVP
 * @github:        https://github.com/guangjieMVP
***********************************************************************/
static inline int stack_validator_init(stack_validator_t *s, int (*check)(struct _stack_validator *s,int val))
{
    if(!s || !check)
        return -1;
    
    s->check = check;
    return 0;
}

/***********************************************************************
 * @brief:         校验方法
 * @param[in]:     None
 * @retval[out]:   None
 * @author:        guangjieMVP
 * @github:        https://github.com/guangjieMVP
***********************************************************************/
static inline int stack_validate(stack_validator_t *s, int val)
{
    if(!s)
        return -1;
    
    if(!s->check)     //没有校验函数 无须校验
        return 0; 

    return s->check(s, val);
}

static inline int stack_validator_deinit(stack_validator_t *s)
{
    s->check = NULL;
    return 0;
}


#endif